package thread;

/**
 * @Description:
 * 创建两个线程 每个线程打印100个数
 * @Author: hmm
 * @CreateDate: 2019/7/25$ 22:10$
 * @UpdateUser: hmm
 * @UpdateDate: 2019/7/25$ 22:10$
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
public class join_Demo {

    private static void excute() {
        Thread A = new Thread(() -> printNum());

        Thread B = new Thread(() -> {
            System.out.format("%s: %s%n", Thread.currentThread().getName(), "开始等待另一个线程");
            try {
                //此行代码实现A线程运行结束后 B才开始运行
                A.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            printNum();
        });
        A.start();
        B.start();
    }

    private static void printNum() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName() + "--------" + i);
        }
    }

    public static void main(String[] args) {
        join_Demo.excute();
    }
}
